package com.bskj.common.dao.core;

import java.util.ArrayList;
import java.util.List;

/**
 * find请求的封装类
 *
 * @author lishi
 * @date 2017-11-29 上午11:56:45
 */
public class FindRequestEntity {
    private List<WhereEntity> whereList = new ArrayList<WhereEntity>();
    private List<OrderEntity> orderList = new ArrayList<OrderEntity>();
    private List<BetweenEntity> betweenList = new ArrayList<BetweenEntity>();
    private List<LikeEntity> likeList = new ArrayList<>();

    private Integer pageNo;
    private Integer pageSize;

    public FindRequestEntity addWhere(String property, WhereEnum whereEnum, Object value) throws Exception {
        WhereEntity whereEntity = new WhereEntity(property, whereEnum, value);
        if (whereList == null) {
            whereList = new ArrayList<WhereEntity>();
        }
        whereList.add(whereEntity);
        return this;
    }

    public FindRequestEntity addOrder(String property, OrderEnum order) throws Exception {
        OrderEntity orderEntity = new OrderEntity(property, order);
        if (orderList == null) {
            orderList = new ArrayList<OrderEntity>();
        }
        orderList.add(orderEntity);
        return this;
    }

    public FindRequestEntity addBetween(String property, String from, String end) {
        BetweenEntity betweenEntity = new BetweenEntity(property, from, end);
        if (betweenList == null) {
            betweenList = new ArrayList<BetweenEntity>();
        }
        betweenList.add(betweenEntity);
        return this;
    }

    public FindRequestEntity addLike(String property, String value) {
        LikeEntity likeEntity = new LikeEntity(property, value);
        if (likeList == null) {
            likeList = new ArrayList<LikeEntity>();
        }
        likeList.add(likeEntity);
        return this;
    }

    public void setPage(Integer pageNo, Integer pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public List<WhereEntity> getWhereList() {
        return whereList;
    }

    public List<OrderEntity> getOrderList() {
        return orderList;
    }

    public List<BetweenEntity> getBetweenList() {
        return betweenList;
    }

    public List<LikeEntity> getLikeList() {
        return likeList;
    }

    public Integer getPageNo() {
        return pageNo;
    }


    public Integer getStartNo() {
        return (pageNo - 1) * pageSize;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public FindRequestEntity getParam() {
        return this;
    }
}
